<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">

	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
		<meta name="description" content="">
		<meta name="author" content="">

		<title>还书操作</title>
		<!-- Bootstrap core CSS -->
		<link href="asserts/css/bootstrap.min.css" th:href="@{/webjars/bootstrap/css/bootstrap.css}" rel="stylesheet">

		<!-- Custom styles for this template -->
		<link href="asserts/css/dashboard.css" th:href="@{/asserts/css/dashboard.css}" rel="stylesheet">		
		<script type="text/javascript" src="asserts/js/jquery-3.2.1.slim.min.js" th:src="@{/webjars/jquery/jquery.js}"></script>
		<script type="text/javascript" src="asserts/js/bootstrap.min.js" th:src="@{/webjars/bootstrap/js/bootstrap.js}"></script>
	
	</head>

	<body>
		<!--引入抽取的topbar-->
		<!--模板名：会使用thymeleaf的前后缀配置规则进行解析-->
		<div th:replace="commons/bar::topbar"></div>

		<div class="container-fluid">
			<div class="row">
				<!--引入侧边栏-->
				<div th:replace="commons/bar::#sidebar(activeUri='bookreturnInput')"></div>

				<main role="main" class="col-md-9 ml-sm-auto col-lg-10 pt-3 px-4">				
				 <form  role="form" th:action=@{/bookreturn} method="post">
				    
					<div class="form-group">
						<label for="bookid" class="col-sm-3 control-label">输入图书编号：</label>
						<input id="bookid" type="text" class="form-control col-xs-6 col-sm-6 col-md-4 col-lg-3" placeholder="数字格式">
						<input type="button" id="addbook" class="btn btn-primary" onclick="getrecord()" value="读待还图书编号" />
					</div>
					<br/>
					<div class="form-group" id="booklist">
					    <h3><label for="book">待还图书列表</label></h3>
					    <table class="table table-striped table-sm">
					    <thead>
						<tr>
							<th>借书人</th>
							<th>图书编号</th>
							<th>书 名</th>
							<th>借阅状态</th>
							<th>借出时间</th>
							<th>最晚归还时间</th>
							<th>续借次数</th>
							<th>操作</th>
						</tr>
					    <tbody >
					    	    
					    </tbody>
					    </table>
				     </div>
				  <button type="submit" class="btn btn-default">提交</button>
				</form>
				</main>
			</div>
		</div>

		<!-- Bootstrap core JavaScript
    ================================================== -->
		<!-- Placed at the end of the document so the pages load faster -->

		<script type="text/javascript">
		
		var bookids = [];
		
		function deleteSelf(obj,id){
			var tr=obj.parentNode.parentNode;
			tr.parentNode.removeChild(tr);
			//取出此图书编号
			bookids.splice($.inArray(id, bookids), 1);
		};

		function getrecord(){
			var bookid=$("#bookid").val();
			 if(bookids.indexOf(bookid) !=-1) 
				 {
				 alert("该书已经被加入待还图书列表！");
				 return ;
		         }
			 else bookids.push(bookid);
			
			 $.get("/bookreturn/" + bookid, 
				 function(data){
				     if(typeof(data.bookID)=="undefined"){
						 alert("提示： 查不到该书的相应借阅记录" );	 
					 }
					 else{
						 var t='<tr><td>'
						       + data.readerName +'</td> <td> <input name="bookid" type="checkbox" checked="checked" value="'+data.bookID+'">'
						       + data.bookID +'</input> </td> <td>'
						       + data.title +'</td> <td>'
						       + data.borrowState +'</td> <td>'
						       + new Date(data.borrowTime).toLocaleDateString() +'</td> <td>'
						       + new Date(data.overTime).toLocaleDateString() +'</td> <td>'
						       + data.renewTime +'</td> <td>'
						       + '<button type="button" class="btn btn-sm btn-danger deleteBtn" onclick="deleteSelf(this,'+data.bookID+');">删 除</button>'
						       +'</td></tr>';

						 $("tbody").append(t);
						 } 
				 });
           };

		</script>
	</body>
</html>